package com.zy.system.exception;

import com.zy.common.result.Result;
import com.zy.common.result.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author Gong
 * @Description 自定义异常
 * @dATE 2023/6/5 8:49
 **/
@Data
//@AllArgsConstructor
//@NoArgsConstructor
@ToString
public class ZyException extends RuntimeException{
    private Integer code;

    private String message;
    /**
     * 通过状态码和错误消息创建异常对象
     * @param code
     * @param message
     */
    public ZyException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 接收枚举类型对象
     * @param resultCodeEnum
     */
    public ZyException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
    }
}
